<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>任务列表</title>
    <style type="text/css" rel="stylesheet">
        table,tr,th,td{
            border: 1px solid black;
            border-collapse: collapse;
        }
        table th{
            text-align: center;
        }
    </style>
</head>
<body>
    <div style="width: 1400px;margin: 20px auto;">
        <div style="margin-top: 30px;">
            <a href="${request.contextPath}/quartz/toAdd">新增</a>
        </div>
        <hr/>
        <c:if test="${param.msg != null && !''.equals(param.msg)}">
            <div style="width: 1400px;border: 1px solid black">
                    ${param.msg}<span style="float: right" class="close">X</span>
            </div>
        </c:if>
        <table>
            <thead>
                <tr>
                    <th>任务组名称</th>
                    <th>任务名称</th>
                    <th>触发器名称</th>
                    <th>触发器组名称</th>
                    <th>执行表达式</th>
                    <th>上次执行时间</th>
                    <th>下次执行时间</th>
                    <th>任务状态</th>
                    <th>开始时间</th>
                    <th>结束时间</th>
                    <th>执行类</th>
                    <th>任务数据</th>
                    <th style="width: 15%;">操作</th>
                </tr>
            </thead>
            <tbody>
                <c:choose>
                    <c:when test="${list != null && list.size() > 0}">
                        <c:forEach items="${list}" var="list">
                            <tr>
                                <td>${list.jobGroup}</td>
                                <td>${list.jobName}</td>
                                <td>${list.triggerName}</td>
                                <td>${list.triggerGroup}</td>
                                <td>${list.cron}</td>
                                <td><fmt:formatDate value="${list.previousFireTime}" pattern="yyyy-MM-dd hh:mm:ss"/></td>
                                <td><fmt:formatDate value="${list.nextFireTime}" pattern="yyyy-MM-dd hh:mm:ss"/></td>
                                <td>
                                    <c:if test="${list.jobStatus == 'NONE'}">
                                        <span class="label">未知</span>
                                    </c:if>
                                    <c:if test="${list.jobStatus == 'NORMAL'}">
                                        <span class="label label-success arrowed">正常运行</span>
                                    </c:if>
                                    <c:if test="${list.jobStatus == 'PAUSED'}">
                                        <span class="label label-warning">暂停状态</span>
                                    </c:if>
                                    <c:if test="${list.jobStatus == 'COMPLETE'}">
                                        <span class="label label-important arrowed-in">完成状态</span>
                                    </c:if>
                                    <c:if test="${list.jobStatus == 'ERROR'}">
                                        <span class="label label-info arrowed-in-right arrowed">错误状态</span>
                                    </c:if>
                                    <c:if test="${list.jobStatus == 'BLOCKED'}">
                                        <span class="label label-inverse">锁定状态</span>
                                    </c:if>
                                </td>
                                <td><fmt:formatDate value="${list.startTime}" pattern="yyyy-MM-dd hh:mm:ss"/></td>
                                <td><fmt:formatDate value="${list.endTime}" pattern="yyyy-MM-dd hh:mm:ss"/></td>
                                <td>${list.jobClass}</td>
                                <td>${list.jobDataMap}</td>
                                <td style="width: auto;text-align: center;">
                                    <a href="${request.contextPath}/quartz/toEdit?jobName=${list.jobName}&jobGroup=${list.jobGroup}"><i class="icon-edit"></i>编辑</a><br>
                                    <a href="javascript:void(0);" onclick="pause('${list.jobName}','${list.jobGroup}');"><i class="icon-edit"></i>暂停</a>
                                    <a href="javascript:void(0);" onclick="resume('${list.jobName}','${list.jobGroup}');"><i class="icon-edit"></i>恢复</a>
                                    <a href="javascript:void(0);" onclick="remove('${list.jobName}','${list.jobGroup}','${list.triggerName}','${list.triggerGroup}');"><i class="icon-edit"></i>删除</a>
                                </td>
                            </tr>
                        </c:forEach>
                    </c:when>
                    <c:otherwise>
                        <tr>
                            <td colspan="13" style="text-align: center">没有数据</td>
                        </tr>
                    </c:otherwise>
                </c:choose>
            </tbody>
        </table>
    </div>
</body>
<script src="${request.contextPath}/static/js/jquery.min.js" rel="script"></script>
<script>
    var perfix_url = "${request.contextPath}";
    $(function () {
        $(".close").click(function () {
            $(this).parent().hide();
        })
    })

    //删除
    function remove(jobName,jobGroup,triggerName,triggerGroup){
        $.post(perfix_url + "/quartz/delete",{"jobName":jobName,"jobGroup":jobGroup,"triggerName":triggerName,"triggerGroup":triggerGroup},function(data){
            if(data.code == 200){
                window.location.href = perfix_url + "/quartz/list?msg=success";
            }else{
                window.location.href = perfix_url + "/quartz/list?msg=faild";
            }
        });
    }

    //暂停任务
    function pause(jobName,jobGroup){
        $.post(perfix_url + "/quartz/pause",{"jobName":jobName,"jobGroup":jobGroup},function(data){
            if(data.code == 200){
                window.location.href = perfix_url + "/quartz/list?msg=success";
            }else{
                window.location.href = perfix_url + "/quartz/list?msg=faild";
            }
        });
    }

    //恢复任务
    function resume(jobName,jobGroup){
        $.post(perfix_url + "/quartz/resume",{"jobName":jobName,"jobGroup":jobGroup},function(data){
            if(data.code == 200){
                window.location.href = perfix_url + "/quartz/list?msg=success";
            }else{
                window.location.href = perfix_url + "/quartz/list?msg=faild";
            }
        });
    }

</script>
</html>
